<template>
  <el-dialog title="流程明细" :visible.sync="dialogVisible" width="80%" style="height:85%" :append-to-body="true">
    <el-table
      :data="tableData"
      style="width: 100%;overflow:auto;height:90%"
      row-key="kid"
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="任务ID" ></el-table-column>
      <el-table-column prop="name" label="任务名称"></el-table-column>
      <!-- <el-table-column prop="owner" label="发布者" ></el-table-column> -->
      <el-table-column prop="assignee" label="执行人"></el-table-column>
      <el-table-column prop="processInstanceId" label="实例ID" ></el-table-column>
      <el-table-column prop="taskDefinitionKey" label="业务key" width="320"></el-table-column>
       <el-table-column prop="processDefinitionId" label="流程定义ID" ></el-table-column>
      <el-table-column prop="startTime" label="发起时间" :formatter="timeFormat"></el-table-column>
      <el-table-column prop="endTime" label="结束时间" :formatter="timeFormat"></el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>
import TreeSelect from "@/components/basic-treeselect/treeselect";
import { activeUrl } from "@/config/env";
const urls = {
  list: activeUrl + "/task/get_list_by_instance"
};
export default {
  data() {
    return {
      dialogVisible: false,
      tableData: [],
      defaultCheckedKeys: [],
      form: {
        objectId: null,
        name: null,
        note: null
      },
      rules: {
        
      }
    };
  },
  components: {
    TreeSelect
  },
  methods: {
    popoverHide(checkedIds, checkedData) {
      this.form.menus = checkedIds.toString();
    },
    show(processInstanceId) {
      this.dialogVisible = true;
      if (this.$refs["closeForm"]) {
        this.$refs["closeForm"].resetFields();
      }
      this.fetch(processInstanceId);
    },
    onSubmit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          axios.post(urls.save, this.form).then(res => {
            this.$message(res.data.result);
            this.dialogVisible = false;
            this.$emit("refresh");
          });
        }
        return false;
      });
    },
    fetch(processInstanceId) {
      axios.get(urls.list,{params : {processInstanceId : processInstanceId}}).then(res => {
        this.tableData = res.data;
      });
    },
    timeFormat(row, column){
       // 工作流时间格式化
      return new Date(+new Date(row.createTime) + 8 * 3600 * 1000)
        .toISOString()
        .replace(/T/g, " ")
        .replace(/\.[\d]{3}Z/, "");
    }
  }
};
</script>